<!-- 首页 -->
<template>
	<view class="home-wrap u-m-b-20">
		<!-- 空白页 -->
		<!-- #ifdef APP-PLUS -->
		<u-no-network @retry="init"></u-no-network>
		<!-- #endif -->
		<shopro-empty v-if="!hasTemplate" :image="IMG_URL + '/imgs/empty/template_empty.png'"
			tipText="暂未找到模板，请前往装修~"></shopro-empty>

		<view v-else-if="isConnected && isRefresh" class="content-box">
			<!-- 导航栏 -->
			<home-head v-if="headSwiperList && headSwiperList.length" :scrollTop="scrollTop" borderRadius="0"
				:navTitle="initShop.name" :list="headSwiperList"></home-head>
			<!-- 自定义模块 -->
			<!-- 分类选项卡 -->
			<view v-if="categoryTabsData  && categoryTabsData.length">
				<sh-category-tabs v-for="(item,index) in categoryTabsData" :key="index" :enable="enable"
					:curCategory="item" :headType="headType"></sh-category-tabs>
			</view>
			<!-- 直播 -->
			<!-- #ifdef MP-WEIXIN -->
			<view v-if="liveList.goods.data.length>0">
				<sh-category-tabs :key="index" :enable="enable" :curCategory="liveList"
					:headType="headType"></sh-category-tabs>
			</view>
			<!-- <sh-live v-if="liveList.length>0 && HAS_LIVE" :detail="liveList"></sh-live> -->

			<!-- #endif -->
			<!-- 登录提示 -->
			<!-- <shopro-auth-modal></shopro-auth-modal> -->
			<!-- 悬浮按钮 -->
			<!-- <shopro-float-btn></shopro-float-btn> -->
			<!-- 连续弹窗提醒 -->
			<!-- <shopro-notice-modal v-if="!showPrivacy && isLogin"></shopro-notice-modal> -->
			<!-- 隐私协议 -->
			<!-- #ifdef APP-PLUS -->
			<!-- <privacy-modal v-if="initShop && initShop.name" v-model="showPrivacy"></privacy-modal> -->
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<!-- <view class="tabbar-hack" style="height: 120rpx; width:100%;"></view> -->
			<!-- #endif -->
		</view>
		<!-- <shopro-tabbar></shopro-tabbar> -->
	</view>
</template>

<script>
	import shBanner from './components/sh-banner.vue';
	import shGridSwiper from './components/sh-grid-swiper.vue';
	import shHotGoods from './components/sh-hot-goods.vue';
	import shAdv from './components/sh-adv.vue';
	import shCoupon from './components/sh-coupon.vue';
	import shSeckill from './components/sh-seckill.vue';
	import shGroupon from './components/sh-groupon.vue';
	import shRichtext from './components/sh-richtext.vue';
	import shTitleCard from './components/sh-title-card.vue';
	import shSearch from './components/sh-search.vue';
	import shCategoryTabs from './components/sh-category-tabs.vue';

	import privacyModal from './index/privacy-modal.vue';
	import homeHead from './index/home-head.vue';

	// #ifdef MP-WEIXIN
	import {
		HAS_LIVE
	} from '@/env';

	import shLive from './components/sh-live.vue';
	// #endif

	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';

	export default {
		components: {
			shBanner,
			shGridSwiper,
			shGroupon,
			shHotGoods,
			shAdv,
			shCoupon,
			shSeckill,
			shRichtext,
			shTitleCard,
			shSearch,
			shCategoryTabs,

			privacyModal,
			homeHead,

			// #ifdef MP-WEIXIN
			shLive
			// #endif
		},
		data() {
			return {
				// #ifdef MP-WEIXIN
				HAS_LIVE: HAS_LIVE,
				// #endif
				isRefresh: true,

				enable: false, //是否开启吸顶。
				isConnected: true, //是否有网
				showPrivacy: false, //协议
				scrollTop: 0,
				headType: 'single',
				headSwiperList: [],
				IMG_URL: this.$IMG_URL,
				tempPic: require('../../static/images/home/temp.png'),
				liveList: {
					name: '照片直播',
					type: 'living',
					id: 4,
					goods: {
						data: []
					}
				}
			};
		},
		computed: {
			...mapGetters(['initShop', 'homeTemplate', 'hasTemplate']),
			// 分类选项卡数据
			categoryTabsData() {
				let that = this
				if (this.homeTemplate?.length) {
					return this.homeTemplate
				}
			},

		},
		onPullDownRefresh() {
			this.init();
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onShow() {
			let that = this;
			this.enable = true;
			// this.isLogin && this.getCartList();
			// 网络变化检测
			that.init()
			uni.onNetworkStatusChange(res => {
				this.isConnected = res.isConnected;
				res.isConnected && this.init();
			});
		},
		onHide() {
			this.enable = false;
		},
		onLoad() {
			// #ifdef APP-VUE
			// plus.runtime.disagreePrivacy();
			// app隐私协议弹窗
			if (!plus.runtime.isAgreePrivacy()) {
				this.showPrivacy = true;
				this.showNoticeModal = false;
			}
			// #endif
		},
		methods: {
			...mapActions(['appInit', 'getTemplate', 'getCartList']),
			// 初始化
			init() {
				this.isRefresh = false;
				let aa = this.getTemplate()
				this.isRefresh = true;
				this.$http('home.getbanner').then(res => {
					if (res.code === 1) {
						this.headSwiperList = res.data
					}
				});
				this.$http('home.broadList').then(res => {
					if (res.code === 1) {
						this.liveList.goods.data = res.data
						// 暂无数据,假数据
						// this.liveList.goods.data = [{
						// 	address: '长津湖',
						// 	title: '岁月静好',
						// 	image: this.tempPic
						// }]
					}
				});
			}
		}
	};
</script>

<style lang="scss"></style>